#include <vtkSmartPointer.h>
#include <vtkImageCanvasSource2D.h>
#include <vtkImageViewer2.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkImageData.h>

int main(int, char *[])
{
  // Create an image
  // vtkSmartPointer<vtkImageCanvasSource2D> canvas =
  //   vtkSmartPointer<vtkImageCanvasSource2D>::New();
  // canvas->SetScalarTypeToUnsignedChar();
  // canvas->SetExtent(0, 100, 0, 100, 0, 0);
  // canvas->SetNumberOfScalarComponents(3);

  // canvas->SetDrawColor(0, 0, 0, 0);
  // canvas->FillBox(0, 100, 0, 100);
  // canvas->SetDrawColor(255, 0, 0, 0);
  // canvas->FillBox(20, 40, 20, 40);
  // canvas->Update();

  vtkSmartPointer<vtkImageData> image = vtkSmartPointer<vtkImageData>::New();
  image->SetDimensions(100, 100, 100);
  image->AllocateScalars(VTK_UNSIGNED_CHAR, 1);
  unsigned char *ptr = static_cast<unsigned char *>(image->GetScalarPointer());
  for (int i = 0; i < 1000000; i++)
  {
    *ptr++ = i % 255;
  }

  vtkSmartPointer<vtkImageViewer2> viewer = vtkSmartPointer<vtkImageViewer2>::New();
  viewer->SetInputData(image);

  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
      vtkSmartPointer<vtkRenderWindowInteractor>::New();
  viewer->SetupInteractor(renderWindowInteractor);
  viewer->GetRenderer()->ResetCamera();
  viewer->Render();
  renderWindowInteractor->Start();
  return EXIT_SUCCESS;
}